package com.device.controller;

import com.device.entity.*;
import com.device.service.ConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

@RestController
@RequestMapping("/api/remoteDevice")
@CrossOrigin(origins = "*")
@Api(tags = "远程设备管理")
public class RemoteDeviceApiController {

    @Autowired
    private ConfigService configService;

    private static final Logger log = LoggerFactory.getLogger(RemoteDeviceApiController.class);

    @GetMapping("/totalConfig/{deviceImei}")
    @ApiOperation(value = "获取远程设备的配置信息", notes = "根据设备IMEI获取远程设备的配置信息")
    public ResponseEntity<TotalConfig> getTotalConfig(
            @ApiParam(value = "设备IMEI", required = true) @PathVariable String deviceImei) {
        SerialPortConfig serialPortConfig = configService.getSerialPortConfig(deviceImei);
        PollingConfig pollingConfig = configService.getPollingConfig(deviceImei);
        NetworkConfig networkConfig = configService.getNetworkConfig(deviceImei);
        TotalConfig totalConfig = new TotalConfig(serialPortConfig,pollingConfig,networkConfig);
        return ResponseEntity.ok(totalConfig);
    }
} 